// 客户,供应商合同模糊查询
import React from 'react';
import { Select, Spin } from 'antd';
import { connect } from 'dva';

const { Option } = Select;
@connect(({ invoice: { contList }, loading }) => ({
  contList,
  loading: loading.effects['invoice/fetchContList'],
}))
class Customer extends React.Component {
  // 获取合同
  search = value => {
    const { dispatch, params = {} } = this.props;
    if (value.trim().length) {
      dispatch({
        type: 'invoice/fetchContList',
        payload: { contName: value.trim(), ...params },
      });
    }
  };

  getData = () => {};

  render() {
    const { contList = [], loading, getData = this.getData } = this.props;
    return (
      <Select
        placeholder="请输入关键字检索"
        {...this.props}
        showSearch
        optionFilterProp="children"
        showArrow={false}
        onSearch={this.search}
        onSelect={(value, options) => getData(value, options)}
        notFoundContent={loading ? <Spin size="small" /> : null}
      >
        {contList.map(item => (
          <Option key={item.contId} title={item.contName}>
            {item.contName}
          </Option>
        ))}
      </Select>
    );
  }
}
export default Customer;
